﻿using Hx.ADSyncPlatform.Db;
using Hx.ADSyncPlatform.Entity.Entities;
using Hx.ADSyncPlatform.Service.Base;
using SqlSugar;
using System;
using System.Collections.Generic;

namespace Hx.ADSyncPlatform.Service
{
    public class Plat_SysRoleService : BaseService<Plat_SysRole>
    {
        protected DbSet<Plat_SysRole> Plat_SysRoleDb;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="db"></param>
        public Plat_SysRoleService(DbContext db) : base(db)
        {
            this.Plat_SysRoleDb = db.DbSet<Plat_SysRole>();
        }



        /// <summary>
        /// 获取全部角色
        /// </summary>
        /// <returns></returns>
        public List<Plat_SysRole> GetRoles()
        {
            return Plat_SysRoleDb.GetList();
        }



        /// <summary>
        /// 根据用户id获取角色
        /// </summary>
        /// <param name="userId"></param>
        /// <returns></returns>
        public List<Plat_SysRole> GetRolesByUserId(Guid userId)
        {

            var list = base.dbClient.Queryable<Plat_SysManager, Plat_SysManagerRole, Plat_SysRole>
                           ((a, b, c) =>
                                new JoinQueryInfos(
                            JoinType.Inner, a.UserId == b.Plat_SysManager_ID,
                            JoinType.Inner, c.RoleID == b.Plat_SysRole_ID)
                            )
                           .Where((a, b, c) => a.UserId == userId)
                            .Select((a, b, c) => c).ToList();

            return list;
        }

    }

}
